package com.github.bobjoy.java.keywords;

import org.junit.Test;

public class FinalDemo {

    @Test
    public void test1() {
        String a = "hello2";
        final String b = "hello";
        String c = "hello";

        String bb = b + 2;
        String cc = c + 2;
        System.out.println(a == bb);
        System.out.println(a == cc);
    }

    @Test
    public void test2() {
        MyClass m1 = new MyClass();
        MyClass m2 = new MyClass();

        System.out.println(m1.i);
        System.out.println(m1.j);
        System.out.println(m2.i);
        System.out.println(m2.j);
    }

    @Test
    public void test3() {
        MyClass m1 = new MyClass();
        StringBuffer sb = new StringBuffer("hello");
        m1.changeValue(sb);
        System.out.println(sb.toString());
    }

}

class MyClass {

    public final double i = Math.random();
    public static double j = Math.random();

    private String s = "";

    public void changeValue(StringBuffer sb) {
        sb = new StringBuffer();
        sb.append("world");
    }

    class MyClazz{
        private String s = "";

        private void m() {
            System.out.println(MyClass.this.s);
        }
    }
}

/**
 * http://www.cnblogs.com/dolphin0520/p/3811445.html
 */
class WithInner {
    class Inner{

    }
}
class InheritInner extends WithInner.Inner {

    // InheritInner() 是不能通过编译的，一定要加上形参
    InheritInner(WithInner wi) {
        wi.super(); //必须有这句调用
    }

    public static void main(String[] args) {
        WithInner wi = new WithInner();
        InheritInner obj = new InheritInner(wi);
    }
}


